{{- if .Values.controlPlane.autoscaling.enabled }}
{{ if .Capabilities.APIVersions.Has "autoscaling/v2" }}
apiVersion: "autoscaling/v2"
{{ else }}
apiVersion: "autoscaling/v1"
{{ end }}
kind: HorizontalPodAutoscaler
metadata:
  name: {{ include "kuma.name" . }}-control-plane
  namespace: {{ .Release.Namespace }}
  labels: {{ include "kuma.cpLabels" . | nindent 4 }}
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: {{ include "kuma.name" . }}-control-plane
  minReplicas: {{ .Values.controlPlane.autoscaling.minReplicas }}
  maxReplicas: {{ .Values.controlPlane.autoscaling.maxReplicas }}
  {{ if .Capabilities.APIVersions.Has "autoscaling/v2" }}
  metrics: {{- toYaml .Values.controlPlane.autoscaling.metrics | nindent 4 }}
  {{ else }}
  targetCPUUtilizationPercentage: {{ .Values.controlPlane.autoscaling.targetCPUUtilizationPercentage }}
  {{- end }}
{{- end }}
